import java.util.*;

public class Main9 {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<>();
        Scanner scanner = new Scanner(System.in);

        //读取输入的字符串
        String s = scanner.nextLine();
        //按照空格分割到数组中
        String[] strings = s.split(" ");

        //第一个是s或e的话 执行循环
        while (strings[0].equals("s") || strings[0].equals("e")) {
            //输入是s的情况
            if (strings[0].equals("s")) {

                //不是字符null就创建String对象 是的话就直接
                if (strings[1].equals("null")) {
                    strings[1] = null;
                }

                if (strings[4].equals("null")) {
                    strings[4] = null;
                }

                if (strings[5].equals("null")) {
                    strings[5] = null;
                }

                Student student = new Student(strings[1], Integer.parseInt(strings[2]),
                        Boolean.getBoolean(strings[3]),
                        strings[4], strings[5]);
                personList.add(student);

                //输入是e的情况
            } else {

                if (strings[1].equals("null")) {
                    strings[1] = null;
                }

                if (!strings[5].equals("null")) {

                    personList.add(new Employee(strings[1], Integer.parseInt(strings[2]),
                            Boolean.getBoolean(strings[3]),
                            new Company(strings[5]), Double.parseDouble(strings[4])));

                } else {
                    personList.add(new Employee(strings[1], Integer.parseInt(strings[2]),
                            Boolean.getBoolean(strings[3]),
                            null, Double.parseDouble(strings[4])));

                }
            }

            s = scanner.nextLine();
            strings = s.split(" ");
        }

        //排序
        Collections.sort(personList);

        s = scanner.nextLine();
        if (!s.equals("exit")) {

            List<Student> stuList = new ArrayList<>();
            List<Employee> empList = new ArrayList<>();

            for (Person person : personList) {
                if (person instanceof Student) {
                    stuList.add((Student) person);
                } else {
                    empList.add((Employee) person);
                }
            }

            Collections.sort(stuList);
            for (Student stu:
                    stuList) {
                System.out.println(stu);
            }

            Collections.sort(empList);
            for (Employee emp:
                    empList) {
                System.out.println(emp);
            }

        }
    }
}

class Company {
    String name;
    public Company(String name) {
        this.name = name;
    }
    public String toString() {
        return name;
    }         //直接返回name
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        } else {
            if (this == obj) {
                return true;
            } else {
                if (obj instanceof Company) {
                    Company company = (Company) obj;
                    if (company.name.equals(this.name)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }//name相同返回true

}

abstract class Person implements Comparable<Person> {
    String name;
    int age;
    boolean gender;

    @Override
    public int compareTo(Person o) {
        if (this.name.compareTo(o.name) > 0) {
            return 1;
        } else if (this.name.compareTo(o.name) < 0) {
            return -1;
        } else {
            if (this.age > o.age) {
                return 1;
            } else if (this.age < o.age) {
                return -1;
            } else {
                return 0;
            }
        }
    }

    public Person(String name, int age, boolean gender) {};

    public String toString() {
        return name + "-" + age + "-" + gender;
    }        //返回"name-age-gender"格式的字符串

    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        } else if (obj == this) {
            return true;
        } else {
            if (obj instanceof Person) {
                Person person = (Person) obj;
                if (person.name.equals(this.name)
                        && person.gender == this.gender
                        && person.age == this.age) {
                    return true;
                }
            }
        }
        return false;
    }  //比较name、age、gender,都相同返回true,否则返回false

}

class Student extends Person{
    String stuNo;
    String clazz;

    //建议使用super复用Person类的相关有参构造函数
    public Student(String name, int age, boolean gender,
                   String stuNo, String clazz) {
        super(name, age, gender);
        this.stuNo = stuNo;
        this.clazz = clazz;
    }
    public String toString() {
        return "Student:" + super.toString() + "-" + stuNo + "-" + clazz;
    }        //返回 “Student:person的toString-stuNo-clazz”格式的字符串
    public boolean equals(Object obj) {
        if (super.equals(obj)) {
            if (obj instanceof Student) {
                Student student = (Student) obj;
                if (student.clazz.equals(this.clazz)
                        && student.stuNo.equals(this.stuNo)) {
                    return true;
                }
            }
        }
        return false;
    } //首先调用父类的equals方法,如果返回true，则继续比较stuNo与clazz。

    @Override
    public int compareTo(Person o) {
        return o.age - this.age;
    }
}

class Employee extends Person{
    Company company;
    double salary;

    //建议使用super复用Person类的相关有参构造函数
    public Employee(String name, int age, boolean gender,
                    Company company,double salary) {
        super(name, age, gender);
        this.company = company;
        this.salary = salary;
    }

    public String toString() {
        return "Employee:" + super.toString() + "-" + company + "-" + salary;
    }         //返回"Employee:person的toString-company-salary"格式的字符串

    public boolean equals(Object obj) {
        if (super.equals(obj)) {
            if (this == obj) {
                return true;
            } else {
                if (obj instanceof Employee) {
                    Employee employee = (Employee) obj;
                    if (employee.salary == this.salary
                            && employee.company.equals(this.company)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }//首先调用父类的equals方法,如果返回true。再比较company与salary。

    @Override
    public int compareTo(Person o) {
        return o.age - this.age;
    }
//比较salary属性时，使用DecimalFormat df = new DecimalFormat("#.#");保留1位小数

}


